package com.cnhaimei.vod.logic;

import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.OnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.view.ViewGroup;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.TextView;
import android.widget.ViewFlipper;

import com.cnhaimei.vod.R;
import com.cnhaimei.vod.net.dq.DQQuery;
import com.cnhaimei.vod.util.Const;

public class HotRankActivity extends VODActivity{
	private int mImageViewHeight = 184;
	private int mImageViewWidth = 185;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setContentView(R.layout.v8_hotrank);
		initView();
		
	}

	//调整中间6个板块的位置
	private void updatePosition()
	{
		DisplayMetrics dMetrics = new DisplayMetrics();
		getWindowManager().getDefaultDisplay().getMetrics(dMetrics);
		float xdpi = dMetrics.widthPixels;//dMetrics.xdpi;
		float ydpi = dMetrics.heightPixels;//dMetrics.ydpi;
		float fScaleX = xdpi / 480;//xdpi / 240;
		float fScaleY = ydpi / 800;//ydpi / 240;

		float fTopBottomScale = xdpi / 540;
		int nHeadHeight = (int)(98 * fTopBottomScale);//(int) (98 * fScaleY);
		int nFootHeight = (int)(116 * fTopBottomScale);//(int) (116 * fScaleY);		
		int nPanelHeight = dMetrics.heightPixels - nHeadHeight - nFootHeight;
		int nPaddingTop = (int)((nPanelHeight - (mImageViewHeight*3 - 22) * fScaleY) / 2);
		View layout = findViewById(R.id.TableLayout01);
		layout.setPadding(0, nPaddingTop, 0, 0);
		
		int nPaddingX = (int)((dMetrics.widthPixels - (mImageViewWidth + 20)*fScaleX*2)/4);
		updateImageViewPos(fScaleX, fScaleY, nPaddingX, R.id.hot_song, R.id.hot_bar, R.id.hot_film, R.id.hot_nothing);		
	}

	protected void updateImageViewPos(float fScaleX, float fScaleY, int paddingX, int... ids) {
		for (int i = 0; i < ids.length; i++) {
			View v = findViewById(ids[i]);
			if (v != null)
			{
				ViewGroup.LayoutParams lp = v.getLayoutParams();
				lp.height = (int)((int)mImageViewHeight * fScaleY);
				lp.width = (int) ((int)mImageViewWidth * fScaleX + paddingX*2);
				v.setLayoutParams(lp);
				((ImageView)v).setScaleType(ScaleType.FIT_XY);
				v.setPadding(paddingX, 0, paddingX, 0);
			}
		}
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		super.onClick(v);
		int id = v.getId();
		Intent intent = null;		
		switch (id) {
		case R.id.hot_song:
			intent = new Intent(Const.Action.ShowAllSongs);	
			intent.putExtra(Const.Key.QUERY_TABLE, DQQuery.TABLE_HOTRANK_SONG);
			intent.putExtra(Const.Key.TITLE_NAME, "歌曲热门");
			break;
		case R.id.hot_bar:
			intent = new Intent(Const.Action.showBarSongs);	
			intent.putExtra(Const.Key.QUERY_TABLE, DQQuery.TABLE_HOTRANK_SONG);
			intent.putExtra(Const.Key.TITLE_NAME, "酒吧热门");
			break;
		case R.id.hot_film:
			intent = new Intent(Const.Action.showFilms);	
			intent.putExtra(Const.Key.QUERY_TABLE, DQQuery.TABLE_HOTRANK_STAR);
			intent.putExtra(Const.Key.TITLE_NAME, "电影热门");
			break;
		}
		
		if (intent != null) {
			HotRankActivity.this.startActivity(intent);
		}
	}
			
	private void initView() {
		showBackBtn(true);
		setTitle("热门排行");

		setClickable( R.id.hot_song, R.id.hot_bar, R.id.hot_film);		
		updatePosition();
	}

}
